<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
  import echarts from 'echarts'
  require('echarts/theme/macarons') // echarts theme
  import resize from './mixins/resize'

  export default {
    mixins: [resize],
    props: {
      className: {
        type: String,
        default: 'chart'
      },
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '100%'
      }
    },
    data() {
      return {
        chart: null
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart()
      })
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      initChart() {
        this.chart = echarts.init(this.$el, 'macarons')

        this.chart.setOption({
          title: {
            text: '储罐公称容积统计图',
            textStyle: {
              // color: '#3b7cbd'
            },
            x: '5%',
            y: '5%'
          },
          tooltip: {
            // trigger: 'item',
            // formatter: '{a} <br/>{b} : {c} ({d}%)'
          },
          legend: {
            data: ['1000 m3','2000 m3','2400 m3','3600 m3','5000 m3','10000 m3'],
            top: '5%',
            left: 'center'
          },
          series: [
            {
              name: '储罐公称容积',
              type: 'pie',
              // roseType: 'radius',
              // radius: '50%',
              // center: ['40%', '60%'],
              data: [14, 2, 3, 4, 6, 2],
              animationEasing: 'cubicInOut',
              // animationDuration: 2600,
              labelLine: {
                show: false
              },
              label: {
                show: false,
                position: 'center'
              },
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        })
      }
    }
  }
</script>
